<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="renderer" content="webkit">
  <title></title>
  <link rel="stylesheet" href="/Public/Admin/css/pintuer.css">
  <link rel="stylesheet" href="/Public/Admin/css/admin.css">
  <script src="/Public/Admin/js/jquery.js"></script>
  <script src="/Public/Admin/js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel margin-top" id="add">
  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 添加班级</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="/Admin/Classes/ClassesAdd">
      <?php if($department != null): ?><div class="form-group">
          <div class="label">
            <label>所属系部：</label>
          </div>
          <div class="field">
            <select name="dep_id" class="input w50">
              <?php if(is_array($department)): foreach($department as $key=>$v): ?><option  value="<?php echo ($v["id"]); ?>" <?php if($v['id'] == $info['dep_id']): ?>selected<?php endif; ?> ><?php echo ($v["name"]); ?></option><?php endforeach; endif; ?>
            </select>
          </div>
        </div>
        <?php else: ?>
        <div class="form-group">
          <div class="label">
            <label>所属系部：</label>
          </div>
          <div class="field">
            <input type="text" class="input w50"  name="dep_id"  readonly placeholder="请先去配置所属系部" data-validate="required:请先去配置产品分类" required />
          </div>
        </div><?php endif; ?>
      <div class="form-group">
        <div class="label">
          <label>班级名称：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="name" value=""  />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 产品列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
  <div class="padding border-bottom">

    <ul class="search" style="padding-left:10px;">
      <form action="/Admin/Classes/index" method="get">
        <ul class="search" style="padding-left:10px;">
          <li>
            <select name="dep_id" class="input" style="width:250px; line-height:17px;display:inline-block">
              <option  value="0"  >全部</option>
              <?php if(is_array($department)): foreach($department as $key=>$v): ?><option  value="<?php echo ($v["id"]); ?>"  <?php if($v['id'] == $dep_id): ?>selected<?php endif; ?> >
                <?php echo ($v["name"]); ?>
                </option><?php endforeach; endif; ?>
            </select>
          </li>
          <li><input type="submit" class="button border-main icon-search" value="搜索"></li>
          <li>
            <button type="button" class="button border-yellow" onclick="window.location.href='/Admin/Product/addProduct'"><span class="icon-plus-square-o"></span> 添加产品</button>
          </li>
        </ul>
      </form>

    </ul>

  </div>
  <table class="table table-hover text-center">
    <tr>
      <th width="100" style=" padding-left:20px;">序号</th>
      <th>班级</th>
      <th>所属系部</th>
      <th>班级人数</th>
      <th>添加时间</th>
      <th width="300px">操作</th>
    </tr>
    <?php if(is_array($lists)): foreach($lists as $key=>$v): ?><tr>
        <td><?php echo ($v["id"]); ?></td>
        <td><?php echo ($v["name"]); ?></td>
        <td><?php echo ($v["depName"]); ?></td>
        <td><?php echo ($v["num"]); ?></td>
        <td><?php echo ($v["add_time"]); ?></td>
        <td><div class="button-group">
          <a class="button border-red" href="javascript:void(0)" onclick="return del(<?php echo ($v["id"]); ?>)"><span class="icon-trash-o"></span> 删除</a>
        </div></td>
      </tr><?php endforeach; endif; ?>
    <tr>
      <td colspan="14">
        <?php if($lists == null): ?>暂无信息
          <?php else: ?>
          <div class="pagelist">
            <a href="/Admin/Classes/index/page/0">首页</a>
            <a href="/Admin/Classes/index/page/<?php echo ($pages['page']-1); ?>">上一页</a>
            <?php if(is_array($pages["num"])): foreach($pages["num"] as $key=>$p): if($p-1 == $pages['page']): ?><span class="current"><?php echo ($p); ?></span>
                <?php else: ?>
                <a href="/Admin/Classes/index/page/<?php echo ($p-1); ?>"><?php echo ($p); ?></a><?php endif; endforeach; endif; ?>
            <a href="/Admin/Classes/index/page/<?php echo ($pages['page']+1); ?>">下一页</a>
            <a href="/Admin/Classes/index/page/<?php echo ($pages['total']); ?>">尾页</a>
          </div><?php endif; ?>
      </td>
    </tr>
  </table>
</div>
<script type="text/javascript">
  function del(id){
    if(confirm("您确定要删除吗?")){
      $.ajax({
        url:"/Admin/Classes/delData",
        type:"get",
        data:{
          'id':id,
          'table':'class'
        },
        success:function(data){
          if(data == 1){
            alert("删除成功");
            location.reload();
          } else if(data == 2) {
            alert("班级下面已有学生注册，无法删除");
            location.reload();
          }
          else alert("删除失败");
        }
      })

    }
  }
</script>

<script>
  $("body").bind("keydown",function(event){
    if (event.keyCode == 116) {
      event.preventDefault(); //阻止默认刷新
      //location.reload();
      //采用location.reload()在火狐下可能会有问题，火狐会保留上一次链接
      location=location;
    }
  })
</script>
</body></html>